<template>
  <div class="top">
    <i :class="iconFold" @click="handleFold"></i>
    <el-breadcrumb separator="/">
      <el-breadcrumb-item v-for="(item, index) in sidebarMenu" :key="index">
        {{ item }}
      </el-breadcrumb-item>
    </el-breadcrumb>
    <div class="user">
      <el-dropdown @command="handleCommand">
        <span class="el-dropdown-link">
          <el-badge is-dot>administrator</el-badge><i class="el-icon-arrow-down el-icon--right"></i>
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item>
            <el-badge value="new">
              通知信息
            </el-badge>
          </el-dropdown-item>
          <el-dropdown-item divided command="quit">退出</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </div>
</template>

<style lang="scss">
  .top i {
    float: left;
    line-height: 60px;
    margin-right: 20px;
    font-size: 25px;
  }
  .top i:hover{
    color: rgb(255,96,1);
  }
  .top .el-breadcrumb {
    float: left;
    line-height: 60px;
  }
  .user {
    float: right;
    line-height: 60px;

    .el-dropdown span i {
      font-size: 12px;
      float: none;
      margin-right: 0;
    }
  }
  .el-dropdown-link:hover {
    color: rgb(255,96,1);
  }
  .el-dropdown-link {
    cursor: pointer;
  }
  .top .el-badge__content.is-fixed {
    top: 18px;
  }
</style>

<script>
import { mapState, mapActions, mapMutations } from 'vuex'
export default {
  data () {
    return {
      imageUrl: require('../../../assets/images/timg.gif'),
      iconFold: 'el-icon-s-fold'
    }
  },
  computed: {
    ...mapState({
      sidebarMenu: state => state.permission.sidebarMenu
    })
  },
  methods: {
    ...mapActions({
      LOGIN_OUT_HANDLE: 'user/LOGIN_OUT_HANDLE'
    }),
    ...mapMutations({
      UPDATE_FOLD: 'UPDATE_FOLD'
    }),
    handleCommand (command) {
      if (command === 'quit') {
        this.LOGIN_OUT_HANDLE() // 清空登录信息
        this.$router.push('/login') // 跳转到登录页
      }
    },
    handleFold () {
      this.UPDATE_FOLD(!this.$store.state.fold)
      if (this.$store.state.fold) {
        this.$data.iconFold = 'el-icon-s-unfold'
      } else {
        this.$data.iconFold = 'el-icon-s-fold'
      }
    }
  }
}
</script>
